import time

from selenium.webdriver.common.by import By

from base.page_base import BasePage


class LoanReviewPage(BasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.loan_management = (By.XPATH, '/html/body/div[1]/div[2]/ul/li[2]/a')
        self.review_management = (By.XPATH, '//*[@id="sidebar"]/ul/li[2]/a/span')
        self.preliminary_review = (By.XPATH, '//*[@id="sidebar"]/ul/li[2]/ul/li[1]/a')
        self.frame1 = (By.XPATH, '//*[@id="iframe_box"]')
        self.search_user = (By.XPATH, '/html/body/div[2]/div[1]/div/ul/li[1]/div/input')
        self.search_btn = (By.XPATH, '/html/body/div[2]/div[1]/div/ul/li[8]/input')
        self.choose = (By.XPATH, '/html/body/div[2]/div[3]/table/tbody/tr[1]')
        self.review_btn = (By.XPATH, '/html/body/div[2]/div[2]/ul/li[2]/a/span')
        self.frame2 = (By.XPATH, '//*[@id="xubox_iframe1"]')
        self.passed_btn = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[3]/td[2]/div/label[1]/input')
        self.label = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[4]/td[2]/div/input')
        self.remarks = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[5]/td[2]/div/textarea')
        self.card = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[6]/td[2]/div/ul/li[1]/input')
        self.save_btn = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[7]/td[2]/input[1]')

    def menu_manager(self):
        self.base_click(self.loan_management)
        self.base_click(self.review_management)
        self.base_click(self.preliminary_review)

    def limit_review_page(self, user):
        self.base_switch_frame(self.frame1)
        self.base_input(self.search_user, user)
        self.base_click(self.search_btn)
        time.sleep(1)
        self.base_click(self.choose)
        self.base_click(self.review_btn)

    def review_operate(self, table, remarks, card):
        self.base_switch_frame(self.frame2)
        self.base_click(self.passed_btn)
        self.base_input(self.label, table)
        self.base_input(self.remarks, remarks)
        self.base_input(self.card, card)
        self.base_click(self.save_btn)
        time.sleep(1)
